package com.aaa.controller.fpa;

import com.aaa.entity.LayData;
import com.aaa.entity.MyPage;
import com.aaa.service.fpa.TFpaSubService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("tFpaSub")
public class TFpaSubController {
    /**
     * 服务对象
     */
    @Autowired
    private TFpaSubService tFpaSubService;

    // 批量导入数据
    @Resource
    private TFpaSubService fileService;
    @PostMapping(value = "/import")
    @ResponseBody
    public LayData storageService(MultipartFile file) {

       fileService.dealFile(file);
       return new LayData(true);
    }

    @GetMapping
    @ResponseBody
    public LayData getAllSub(MyPage myPage){

        return new LayData(fileService.getAll(myPage));
    }

    /**
     * fpa做题页面
     * @param myPage
     * @param request
     * @return
     */
    @GetMapping("index")
    public String getIndexAllSub(MyPage myPage, HttpServletRequest request){
        myPage.setLimit(30);
        myPage.setPage(1);
        PageInfo all = fileService.getAll(myPage);
        request.setAttribute("allsub",all);

        return "/fpa/index";

    }
}

